﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Entities;

namespace AbpToDomain.EntityInfo
{
    public class SowingWall : Entity
    {

        [Key]
        public Guid SowingWall_Id { get; set; }
        public string SowingWall_Name { get; set; }
        public string SowingWall_Code {  get; set; }
        public int? Xaxis { get; set; }
        public int? Yaxis { get; set; }
        public string? Mchine { get; set; }
        public override object?[] GetKeys()
        {
           return new object?[] { SowingWall_Id };
        }
        //foreign key
        public List<SowingWallLine> sowingWallLines { get; set; }=new List<SowingWallLine>();
        //method
        public SowingWall AddSowingWall(string SowingWall_Name, string SowingWall_Code,  int? Xaxis, int? Yaxis,string Machine)
        {
            try
            {
                string nullString = null;
                int length = nullString.Length; // 这将引发 NullReferenceException
                this.SowingWall_Name = SowingWall_Name;
                this.SowingWall_Code = SowingWall_Code;
                this.Yaxis = Yaxis;
                this.Mchine = Machine;
                for (int i = 1; i <= Yaxis; i++)
                {
                    for (int a = 1; a <= Xaxis; a++)
                    {
                        SowingWallLine sowingWallLine = new SowingWallLine();
                        sowingWallLine.AddSowingWallLine($"{SowingWall_Code}-{i}-{a}", i, a, Machine);
                        this.sowingWallLines.Add(sowingWallLine);
                    }

                }
                return this;
            }
            catch (Exception)
            {
                return null;
            }
        }

    }

    public class SowingWallLine : Entity
    {
        [Key]
        public Guid SowingWallLine_Id { get; set; }
        public string SowingWallLine_Name { get; set; }
        public int? Xaxis { get; set; }
        public int? Yaxis { get; set; }
        public string? Mchine { get; set; }
        public bool IsOccupy { get; set; }
        public bool OrderIsfinish { get; set; }
        public string? Info { get; set; }
        [Comment("是否亮灯")]
        public bool IsLight {  get; set; }
        public override object?[] GetKeys()
        {
            return new object?[] { SowingWallLine_Id };
        }
        //foreign key
        public SowingWall SowingWall { get; set; }
        //method
        public SowingWallLine AddSowingWallLine(string SowingWallLine_Name,int? Xaxis, int? Yaxis,string Machine)
        {
            this.SowingWallLine_Name = SowingWallLine_Name;
            this.Xaxis = Xaxis;
            this.Yaxis = Yaxis;
            this.Mchine = Machine;
            return this;
        }
        public SowingWallLine Update_IsOccupy_IsLight_Info(string SowingWallLine_Name)
        {
            this.IsOccupy = false;
            this.IsLight = false;
            this.OrderIsfinish = false;
            this.Info = null;
            return this;
        }
    }
}
